package com.example.juegot;

import java.util.ArrayList;
import java.util.List;

import microsoft.mappoint.TileSystem;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.ItemizedOverlayWithFocus;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.PathOverlay;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.MotionEvent;

public class capa extends ItemizedOverlayWithFocus<OverlayItem> {
	 
    private Context contexto;

	public capa(Context contexto,List<OverlayItem> pList,org.osmdroid.views.overlay.ItemizedIconOverlay.OnItemGestureListener<OverlayItem> pOnItemGestureListener) {
 
        super(contexto,pList,pOnItemGestureListener);
        // TODO Auto-generated constructor stub
        this.contexto=contexto;
 
    }
 
    @Override
    public void draw(Canvas canvas, MapView mapview, boolean arg2) {
        // TODO Auto-generated method stub
        super.draw(canvas, mapview, arg2);
 
        if (this.size() > 0) {
 
            for (int i = 0; i < this.size(); i++) {
                GeoPoint in = getItem(i).getPoint();
 
                Point out = new Point();
                mapview.getProjection().toPixels(in, out);
 
                Bitmap bm = BitmapFactory.decodeResource(contexto.getResources(), R.drawable.user);
                canvas.drawBitmap(bm, out.x - bm.getWidth() / 2, out.y - bm.getHeight() / 2, null);
            }
        }
        
    }   
 
    @Override
    public boolean onSingleTapUp(MotionEvent event, MapView mapView) {
        // TODO Auto-generated method stub
        // return super.onSingleTapUp(event, mapView);
        return true;
    }
    public PathOverlay dibujarLinea(ArrayList<GeoPoint> puntosLinea){
    	
    	ArrayList<OverlayItem> listaItemsIconos = new ArrayList<OverlayItem>();
    	PathOverlay lineaOverlay = new PathOverlay(Color.BLUE, mResourceProxy);
	    if (puntosLinea != null) {
		int i=0;
		for (GeoPoint p : puntosLinea) {
		    lineaOverlay.addPoint((int) (p.getLatitudeE6()),
			    (int) (p.getLongitudeE6()));
		    if(i==0){
			//estrella
			OverlayItem overlayDibujo = new OverlayItem(
				"Inicio de la Ruta!!!", 
				"", 
				p);
			overlayDibujo.setMarker(contexto.getResources().getDrawable(R.drawable.star32));
			listaItemsIconos.add(overlayDibujo);
			i++;
		    }else if(i==puntosLinea.size()-1){
			//meta
			OverlayItem overlayDibujo = new OverlayItem("Fin de la Ruta!!!","",p);
			overlayDibujo.setMarker(contexto.getResources().getDrawable(R.drawable.arrow));
			listaItemsIconos.add(overlayDibujo);
			i++;
		    }else{
			i++;
		    }
		}
		
	    }
	    return lineaOverlay;
    }
}